package com.app.service.impl;

import com.app.mapper.jiuquan.SpecialityManageMapper;
import com.app.mapper.jiuquan.TrainSpecialityMapper;
import com.app.model.SpecialityManageModel;
import com.app.service.SpecialityManageService;
import com.app.util.StringTool;
import com.app.vo.IdNameChildrenVo;
import com.app.vo.IdNameVo;
import com.app.vo.SpecialityManageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SpecialityManageServiceImpl extends ServiceImpl<SpecialityManageMapper, SpecialityManageModel> implements SpecialityManageService {
    @Autowired
    private SpecialityManageMapper specialityManageMapper;

    @Autowired
    private TrainSpecialityMapper trainSpecialityMapper;

    //专业管理列表
    @Override
    public SpecialityManageVo getSpecialityManageList(Integer page, Integer limit, String name) {
        Page<SpecialityManageModel> page1 = new Page<>(page, limit);
        QueryWrapper<SpecialityManageModel> qw = new QueryWrapper<>();
        if (StringTool.isNotEmpty(name)) {
            qw.like("name", name);
        }
        Page<SpecialityManageModel> specialityManagePage = specialityManageMapper.selectPage(page1, qw);

        List<SpecialityManageModel> SpecialityManageList = specialityManagePage.getRecords();

        long count = specialityManagePage.getTotal();
        SpecialityManageVo specialityManageVo = new SpecialityManageVo();
        specialityManageVo.setList(SpecialityManageList);
        specialityManageVo.setCount((int) count);
        return specialityManageVo;
    }

    //根据培训学校ID查专业列表
    @Override
    public List<IdNameChildrenVo> getSpecialityByTrainId(Integer trainId) {
        List<IdNameChildrenVo> vo = new ArrayList<>();
        //创业培训
        List<Integer> type1 = trainSpecialityMapper.getSpecialityList(trainId, 1);
        IdNameChildrenVo vo1 = new IdNameChildrenVo();
        vo1.setId(1);
        vo1.setName("创业培训");
        if (type1.size() != 0) {
            List<IdNameVo> specialityInfo = specialityManageMapper.getSpecialityInfo(type1);
            vo1.setChildren(specialityInfo);
            vo.add(vo1);
        }
        //技能培训
        List<Integer> type2 = trainSpecialityMapper.getSpecialityList(trainId, 2);
        IdNameChildrenVo vo2 = new IdNameChildrenVo();
        vo2.setId(2);
        vo2.setName("技能培训");
        if (type2.size() != 0) {
            List<IdNameVo> specialityInfo = specialityManageMapper.getSpecialityInfo(type2);
            vo2.setChildren(specialityInfo);
            vo.add(vo2);
        }
        return vo;
    }

    //查询所有专业列表ID,Name
    @Override
    public List<IdNameVo> getSpecialityIdName() {
        List<IdNameVo> specialityIdName = specialityManageMapper.getSpecialityIdName();
        return specialityIdName;
    }
}
